<?php

namespace plugin\admin\app\controller;

use app\service\YouYinService;
use plugin\admin\app\model\PhoneDn;
use support\exception\BusinessException;
use support\Request;
use support\Response;

/**
 * 分机绑定
 */
class DnController extends Base
{

    //真实分机号
    public function index(Request $request)
    {
        return view('dn/index');
    }


    //分机列表
    public function select(Request $request)
    {
        $page = $request->get('page', 1);
        $limit = $request->get('limit', 10);
        $res = (new YouYinService())->dn_list($page, $limit);
        //总条数
        $total = $res['data']['total'];
        return json(['code' => 0, 'data' => $res['data']['rows'], 'count' => $total]);
    }




    //解绑
    public function delete(Request $request)
    {

        $dns = $request->post('dns');
        foreach ($dns as $dn) {
            if (!$dn) {
                return $this->json(500, '请选择分机');
            }
            $res = (new YouYinService())->unbind($dn);
        }


        return $this->json(0);
    }


}
